package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.ItemCat;
import com.bwie.service.ItemCatService;
import com.bwie.mapper.ItemCatMapper;
import com.bwie.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author 61630
* @description 针对表【tb_item_cat(商品类目)】的数据库操作Service实现
* @createDate 2024-08-15 16:20:03
*/
@Service
public class ItemCatServiceImpl extends ServiceImpl<ItemCatMapper, ItemCat>
    implements ItemCatService{

    @Resource
    private ItemCatMapper itemCatMapper;

    @Override
    public R getTreeList() {
        List<ItemCat> itemCatList=itemCatMapper.getTreeList();
        return R.success(itemCatList);
    }

    @Override
    public R delTree(Long id) {

        LambdaQueryWrapper<ItemCat> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ItemCat::getParentId,id);
        List<ItemCat> itemCatList = itemCatMapper.selectList(wrapper);
        for (ItemCat itemCat : itemCatList) {
            delTree(itemCat.getId());
        }
        itemCatMapper.deleteById(id);
        return R.success();
    }

    @Override
    public R insertData(ItemCat itemCat) {
        itemCatMapper.insert(itemCat);
        return R.success();
    }
}




